package com.ocm.tourism.core.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Configurable
public class SaleOff {

   @NotEmpty
   @Size(max = 255)
   private String title;

   @NotEmpty
   @Size(max = 4000)
   private String content;

   @NotNull
   @DateTimeFormat(pattern="dd/MM/yyyy")
   private Date startDate;

   @NotNull
   @DateTimeFormat(pattern="dd/MM/yyyy")
   private Date endDate;

   @OneToOne
   private ScheduleTour scheduleTour;

   @ManyToOne
   private Hotel hotel;

   @OneToOne(cascade=CascadeType.ALL)
   private Advertisement advertisement; 

   private Date modifiedDate;
   
   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }
   
   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_SALEOFF")
   @TableGenerator(name = "GEN_SALEOFF", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "SALEOFF")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   public String getContent() {
      return content;
   }

   public void setContent(String content) {
      this.content = content;
   }


   public Date getStartDate() {
      return startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   public Date getEndDate() {
      return endDate;
   }

   public void setEndDate(Date endDate) {
      this.endDate = endDate;
   }

   public ScheduleTour getScheduleTour() {
      return scheduleTour;
   }

   public void setScheduleTour(ScheduleTour scheduleTour) {
      this.scheduleTour = scheduleTour;
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   public Advertisement getAdvertisement() {
      return advertisement;
   }

   public void setAdvertisement(Advertisement advertisement) {
      this.advertisement = advertisement;
   }

   public Hotel getHotel() {
      return hotel;
   }

   public void setHotel(Hotel hotel) {
      this.hotel = hotel;
   }

   public Date getModifiedDate() {
      return modifiedDate;
   }

   public void setModifiedDate(Date modifiedDate) {
      this.modifiedDate = modifiedDate;
   }

   @Override
   public boolean equals(Object obj) {
      SaleOff room = (SaleOff) obj;
      if (room.getId()!=null && this.getId()!=null){
         return room.getId().longValue() == this.getId().longValue();
      }
      return super.equals(obj);
   }
}
